package utils

import (
	"cachecron/global"
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
)

func InitMysql() *sql.DB {
	dsn := global.App.Configuration.Database.UserName + ":" + global.App.Configuration.Database.PassWord +
		"@tcp(" + global.App.Configuration.Database.Address + ":" + global.App.Configuration.Database.Port + ")/" + global.App.Configuration.Database.DBname

	open, err := sql.Open("mysql", dsn)
	if err != nil {
		panic(err)
	}
	err = open.Ping()
	if err != nil {
		panic(err)
	}
	return open
}
